<?php

namespace app\api\model;

use app\common\model\BaseModel;

class Driver extends BaseModel
{
    // 表名
    protected $name = 'driver';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
    ];

    /**
     * 获取列表
     * @param array $where
     * @param string $field
     * @param int $page
     * @param int $limit
     * @return Driver[]|array|\think\Collection
     */
    public static function getList($where = [], $field = 'id,user_id,driver_name,driver_number,createtime', $page = 1, $limit = 10){
        if($page){
            return self::where($where)->field($field)->order('id', 'desc')->page($page, $limit)->select();
        }else{
            return self::where($where)->field($field)->order('id', 'desc')->select();
        }
    }

    /**
     * 获取单条
     * @param array $where
     * @param string $field
     * @return Driver|array|mixed|\think\Model|null
     */
    public static function getFind($where = [], $field = 'id,user_id,driver_name,driver_number,createtime'){
        return self::where($where)->field($field)->order('createtime', 'desc')->find();
    }
}
